#ifndef __LWIP_DNS_H__
#define __LWIP_DNS_H__

#include "lwip/opt.h"
#include "lwip/netif.h"
#include "lwip/udp.h"

#define RESP_TIMEOUT        100  // wait for 1 second at most for each request
#define DNS_SERVER_PORT     53
#define DNS_PKT_LENGTH      256  // allocate this amount of buffer for query payload.
#define MAX_DOMAIN_NAME_LEN 128

__packed struct dns_hdr
{
        u16_t id;
        u16_t flags;
        u16_t tot_que;
        u16_t tot_ans;
        u16_t tot_auth;
        u16_t tot_add;        
};

// flags
#define DNS_RESPONSE        (1 << 15)
#define DNS_QUERY           0

#define DNS_SQUERY           0          // standard query
#define DNS_IQUERY          (1 << 11)   // inverse query

#define DNS_AA              (1 << 10)
#define DNS_TC              (1 << 9)
#define DNS_RD              (1 << 8)
#define DNS_RA              (1 << 7)
#define DNS_Z               (1 << 6)
#define DNS_AD              (1 << 5)
#define DNS_CD              (1 << 4)

#define DNS_RCODE_NO_ERR    0
#define DNS_RCODE_FMT_ERR   1
#define DNS_RCODE_SRV_FAIL  2
#define DNS_RCODE_NAME_ERR  3
#define DNS_RCODE_NOT_IMP   4
#define DNS_RCODE_REFUSED   5

err_t dns_start(struct netif *netif, char *host, struct ip_addr *addr);


#endif